<template>
    <page-header-wrapper>
        <a-card :bordered="false">
            <div class="table-page-search-wrapper">
                <i-filter :loading="loading" @query="query"/>
                <s-table :loading="loading" :cols="cols" :data="data" :actions="acts"
                         :pagination="pagination" @change="change"/>
            </div>
        </a-card>
    </page-header-wrapper>
</template>

<script>
    import STable from '@/components/Table/PagerTable'
    import IFilter from '@/components/Filter/InterviewTodoFilter'
    import API from "@/api"
    import Adapter from "@/utils/adapter"

    export default {
        components: {
            STable,
            IFilter
        },
        data() {
            return {
                memberMap: {},
                members: [],

                loading: true,
                data: [],
                cols: [{title: '面试地点', key: 'arrangedPlace'}, {title: '面试时间', key: 'arrangedTime'},
                    {title: '面试官', key: 'interviewers'}],
                acts: [{func: this.view, title: '简历'}],
                pagination: {
                    total: 0,
                    current: 1,
                    pageSize: 10,
                    showSizeChanger: true,
                    showQuickJumper: true
                },
                queryParams: {
                    resultType: 0,
                    limit: 10,
                    offset: 0
                }
            }
        },
        mounted() {
            API.User.List().then((res) => {
                if (res) {
                    this.members = res.data || []
                    this.memberMap = {}
                    this.members.forEach((item) => this.memberMap[item.id] = item.name)
                    this.query()
                }
            })
        },
        methods: {
            change() {
                this.queryParams.limit = this.pagination.pageSize
                this.queryParams.offset = (this.pagination.current - 1) * this.pagination.pageSize
                this.query()
            },
            query(params) {
                this.loading = true
                if (params) this.queryParams.resultType = params
                API.Interview.List(this.queryParams).then((res) => {
                    if (res) {
                        this.pagination.total = res.total
                        Adapter.Interview(res.data, this.memberMap)
                        this.data = res.data
                    }
                }).finally(() => this.loading = false)
            },
            view(record) {
                this.$router.push({name: 'interviewTodoDetails', params: {id: record.id, back: '/todo/interview'}})
            }
        }
    }
</script>
